//
//  LoginView.m
//  UI-word-13_豆瓣
//
//  Created by lanou3g on 15/8/25.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LoginView.h"


@implementation LoginView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews{
    //用户名
    _userLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width / 12 * 1,90 ,self.frame.size.width / 5  , 40)];
    _userLabel.text = @"用户名";
    _userLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:_userLabel];
    _userTextField = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width / 5 + 40, 90, self.frame.size.width / 5  * 3 , 40)];
    _userTextField.placeholder = @"请输入用户名";
    _userTextField.font = [UIFont systemFontOfSize:20];
    _userTextField.tag = 101;
    _userTextField.delegate = self;
    _userTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:_userTextField];
    
    //密码
    _passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 160, 80, 40)];
    _passwordLabel.text = @"密码";
    _passwordLabel.font = [UIFont systemFontOfSize:20];
    [self addSubview:_passwordLabel];
    _passwordTextField = [[UITextField alloc]initWithFrame:CGRectMake(self.frame.size.width / 5 + 40, 160, self.frame.size.width / 5  * 3 , 40)];
    _passwordTextField.placeholder = @"请输入密码";
    _passwordTextField.font = [UIFont systemFontOfSize:20];
    _passwordTextField.tag = 102;
    _passwordTextField.delegate = self;
    _passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:_passwordTextField];
    
    //登陆按钮
    _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _loginButton.frame = CGRectMake(self.frame.size.width / 12, 270, self.frame.size.width / 6 * 2, 40);
    _loginButton.layer.masksToBounds = YES;
    _loginButton.layer.cornerRadius = 5.0;
    [_loginButton setTitle:@"登陆" forState:UIControlStateNormal];
    _loginButton.backgroundColor = [UIColor colorWithRed:174/255.0 green:214/255.0 blue:97/255.0 alpha:1];
    //[_loginButton addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
    [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_loginButton];
    
    //注册按钮
    _registButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _registButton.frame = CGRectMake(self.frame.size.width / 12 + self.frame.size.width / 6 * 2 + 40, 270, self.frame.size.width / 6 * 2, 40);
    _registButton.layer.masksToBounds = YES;
    _registButton.layer.cornerRadius = 5.0;
    [_registButton setTitle:@"注册" forState:UIControlStateNormal];
    _registButton.backgroundColor = [UIColor colorWithRed:230/255.0 green:136/255.0 blue:56/255.0 alpha:1];
    [_registButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_registButton];
    
    
    //新浪微博登陆按钮
    _wxloginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _wxloginButton.frame = CGRectMake(self.frame.size.width / 12, 470, self.frame.size.width / 6 * 2, 40);
    _wxloginButton.layer.masksToBounds = YES;
    _wxloginButton.layer.cornerRadius = 5.0;
    [_wxloginButton setTitle:@"微信登陆" forState:UIControlStateNormal];
    _wxloginButton.backgroundColor = [UIColor colorWithRed:174/255.0 green:214/255.0 blue:97/255.0 alpha:1];
    //[_loginButton addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
    [_wxloginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_wxloginButton];

    //qq登陆按钮
    _qqloginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _qqloginButton.frame = CGRectMake(self.frame.size.width / 12 + 200, 470, self.frame.size.width / 6 * 2, 40);
    _qqloginButton.layer.masksToBounds = YES;
    _qqloginButton.layer.cornerRadius = 5.0;
    [_qqloginButton setTitle:@"微信登陆" forState:UIControlStateNormal];
    _qqloginButton.backgroundColor = [UIColor colorWithRed:174/255.0 green:214/255.0 blue:97/255.0 alpha:1];
    //[_loginButton addTarget:self action:@selector(loginButton:) forControlEvents:UIControlEventTouchUpInside];
    [_qqloginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self addSubview:_qqloginButton];

    
    
    
}


//让下一个textField成为第一响应者
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSInteger tag = textField.tag;
    if (tag != 102) {
        [[self viewWithTag:tag+1] becomeFirstResponder];
        return YES;
    } else {
        [textField resignFirstResponder];
        return YES;
    }
}

//点击空白处回收键盘
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}








@end